﻿import QtQuick 2.15
import QtQuick.Controls 2.15

Item {
    width: screenWidth
    height: screenHeight

    Item{
        id:backGround
        anchors.fill: parent
    }

    Rectangle{
        anchors.fill: backGround
        color: "#09295c"
    }

    property int selectIndex : -1       // 当前选中的列表对象
    property string selectName: ""      // 当前选中的型材名称
    property string selectNumber: ""        // 当前选中的型材编号


    // 一键写入的属性
    property string w_knife: ""
    property string w_roller: ""

    property string w_stress01: ""
    property string w_stress02: ""
    property string w_stress03: ""

    property string w_fwdknife01: ""
    property string w_fwdknife02: ""
    property string w_fwdknife03: ""

    property string w_backKnife01: ""
    property string w_backKnife02: ""
    property string w_backKnife03: ""

    Rectangle{
        anchors.top: backGround.top
        anchors.topMargin: 210
        anchors.left: backGround.left
        anchors.leftMargin: 10
        color: "#0b49b0"
        border.width: 1
        border.color: "#008edd"
        width: 480
        height: 1180

        Rectangle{
            width: 150
            height: 40
            anchors.top: parent.top
            anchors.topMargin: 30
            anchors.left: parent.left
            anchors.leftMargin: 120
            color: "transparent"

            Text{
                anchors.centerIn: parent
                font.bold: true
                font.pixelSize: 30
                color: "white"
                text:"当前值"
            }
        }

        Rectangle{
            width: 150
            height: 40
            anchors.top: parent.top
            anchors.topMargin: 30
            anchors.right: parent.right
            anchors.rightMargin: 30
            color: "transparent"

            Text{
                anchors.centerIn: parent
                font.bold: true
                font.pixelSize: 30
                color: "white"
                text:"设定值"
            }
        }


        Column{     // 参数展示框列表
            id:parameterShowColunm
            anchors.top: parent.top
            anchors.topMargin: 100
            spacing: 40
            Repeater{
                model:11
                Row{
                    Item{
                        width: 475
                        height: 60

                        Text{
                            anchors.verticalCenter: parent.verticalCenter
                            anchors.left: parent.left
                            anchors.leftMargin: 20
                            font.pixelSize: 30
                            color: "white"
                            text: index == 0 ? "刀盘" :
                                  index == 1 ? "胶辊" :
                                  index == 2 ? "压力1":
                                  index == 3 ? "压力2":
                                  index == 4 ? "压力3":
                                  index == 5 ? "前刀1":
                                  index == 6 ? "前刀2":
                                  index == 7 ? "前刀3":
                                  index == 8 ? "后刀1":
                                  index == 9 ? "后刀2":
                                               "后刀3"
                        }

                        Rectangle{
                            width: 150
                            height: 50
                            border.width: 1
                            anchors.right: parent.right
                            anchors.rightMargin: 200
                            anchors.verticalCenter: parent.verticalCenter
                            color: "pink"
                            Text{
                                anchors.centerIn: parent
                                font.pixelSize: 30
                                text:index === 0 ? Cpp_Connect.knifeCurrLocation :
                                     index === 1 ? Cpp_Connect.rollerCurrLocation :
                                     index === 2 ? Cpp_Connect.stress01CurrLocation :
                                     index === 3 ? Cpp_Connect.stress02CurrLocation :
                                     index === 4 ? Cpp_Connect.stress03CurrLocation :
                                     index === 5 ? Cpp_Connect.f_knife01CurrLocation :
                                     index === 6 ? Cpp_Connect.f_knife02CurrLocation :
                                     index === 7 ? Cpp_Connect.f_knife03CurrLocation :
                                     index === 8 ? Cpp_Connect.b_knife01CurrLocation :
                                     index === 9 ? Cpp_Connect.b_knife02CurrLocation :
                                                   Cpp_Connect.b_knife03CurrLocation
                            }
                        }
                        Rectangle{
                            width: 150
                            height: 50
                            border.width: 1
                            anchors.right: parent.right
                            anchors.rightMargin: 20
                            anchors.verticalCenter: parent.verticalCenter
                            color: "lightgreen"
                            Text{
                                anchors.centerIn: parent
                                font.pixelSize: 30
                                text:index === 0 ? Cpp_Connect.knifeAimLocation :
                                     index === 1 ? Cpp_Connect.rollerAimLocation :
                                     index === 2 ? Cpp_Connect.stress01AimLocation :
                                     index === 3 ? Cpp_Connect.stress02AimLocation :
                                     index === 4 ? Cpp_Connect.stress03AimLocation :
                                     index === 5 ? Cpp_Connect.f_knife01AimLocation :
                                     index === 6 ? Cpp_Connect.f_knife02AimLocation :
                                     index === 7 ? Cpp_Connect.f_knife03AimLocation :
                                     index === 8 ? Cpp_Connect.b_knife01AimLocation :
                                     index === 9 ? Cpp_Connect.b_knife02AimLocation :
                                                   Cpp_Connect.b_knife03AimLocation
                            }
                        }
                    }
                }
            }
        }

    }

    Rectangle{
        anchors.top: backGround.top
        anchors.topMargin: 210
        anchors.right: backGround.right
        anchors.rightMargin: 10
        border.width: 1
        border.color: "#008edd"
        width: 560
        height: 1180

        Row{        // 列表标题
            z:10
            Repeater{
                model:3
                Rectangle{
                    width: 186
                    height: 60
                    border.width: 1
                    border.color: "white"
                    color: "black"
                    Text{
                        anchors.centerIn:  parent
                        font.pixelSize: 30
                        color: "white"
                        text: index === 0 ? "序号" : index === 1 ? "型材名称" : "型材编号"
                    }
                }
            }
        }

        ListView{
            id:listShow
            y:60
            width: 580
            height: 1180 - 60
            // focus: true
            boundsBehavior: Flickable.StopAtBounds
            property real lastCurrentIndex: -1
            model:Cpp_ItemModel
            ScrollBar.vertical: ScrollBar {
                width: 10
                policy: ScrollBar.AlwaysOn
                visible: true // 确保滚动条可见
            }

            delegate:
                Rectangle {
                width: 558
                height: 60
                // color: ListView.isCurrentItem ? "#1E90FF" : "#FFFFFF"
                color: selectIndex === index ? "#1E90FF" : "#FFFFFF"

                MouseArea{
                    anchors.fill: parent
                    propagateComposedEvents: true
                    onClicked: {
                        listShow.currentIndex = index;
                        selectIndex = index;
                        selectName =matterNameShow.text
                        selectNumber =matterNumberShow.text
                        console.log(knife_select.text+" "+roller_select.text+" "+
                                    stress01_select.text+" "+stress02_select.text+" "+stress03_select.text+" "+
                                    f_knife01_select.text+" "+f_knife02_select.text+" "+f_knife03_select.text+" "+
                                    b_knife01_select.text+" "+b_knife02_select.text+" "+b_knife03_select.text)
                        // 将点击后的属性赋值给一键写入属性

                        w_knife = knife_select.text
                        w_roller = roller_select.text

                        w_stress01 = stress01_select.text
                        w_stress02 = stress02_select.text
                        w_stress03 = stress03_select.text

                        w_fwdknife01 = f_knife01_select.text
                        w_fwdknife02 = f_knife02_select.text
                        w_fwdknife03 = f_knife03_select.text

                        w_backKnife01 = b_knife01_select.text
                        w_backKnife02 = b_knife02_select.text
                        w_backKnife03 = b_knife03_select.text

                    }
                }

                Rectangle{      // 序号
                    id:orderCol
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.left: parent.left
                    width: 186
                    height: 60
                    border.width: 1
                    color: "transparent"
                    Text{
                        anchors.centerIn: parent
                        font.pixelSize: 30
                        text:(index + 1)
                    }
                }
                Rectangle{          // 型材名称
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.left: parent.left
                    anchors.leftMargin: 186
                    width: 187
                    height: 60
                    border.width: 1
                    color: "transparent"
                    Text{
                        id:matterNameShow
                        anchors.centerIn: parent
                        font.pixelSize: 30
                        text:Name
                    }
                }
                Rectangle{      // 型材编号
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.left: parent.left
                    anchors.leftMargin: 373
                    width: 186
                    height: 60
                    border.width: 1
                    color: "transparent"
                    Text{
                        id:matterNumberShow
                        anchors.centerIn: parent
                        font.pixelSize: 30
                        text:Number
                    }
                }
                Text{
                    id:knife_select
                    visible: false
                    text:Knife
                }
                Text{
                    id:roller_select
                    visible: false
                    text:Roller
                }
                Text{
                    id:stress01_select
                    visible: false
                    text:Stress01
                }
                Text{
                    id:stress02_select
                    visible: false
                    text:Stress02
                }
                Text{
                    id:stress03_select
                    visible: false
                    text:Stress03
                }
                Text{
                    id:f_knife01_select
                    visible: false
                    text:F_Knife01
                }
                Text{
                    id:f_knife02_select
                    visible: false
                    text:F_Knife02
                }
                Text{
                    id:f_knife03_select
                    visible: false
                    text:F_Knife03
                }
                Text{
                    id:b_knife01_select
                    visible: false
                    text:B_Knife01
                }
                Text{
                    id:b_knife02_select
                    visible: false
                    text:B_Knife02
                }
                Text{
                    id:b_knife03_select
                    visible: false
                    text:B_Knife03
                }
            }
        }
    }

    Rectangle{
        anchors.top: backGround.top
        anchors.topMargin: 1410
        anchors.left: backGround.left
        anchors.leftMargin: 10
        color: "#0b49b0"
        border.width: 1
        border.color: "#008edd"
        width: 480
        height: 60

        Text{
            anchors.verticalCenter: parent.verticalCenter
            anchors.left: parent.left
            anchors.leftMargin: 10
            font.pixelSize: 30
            font.bold: true
            color: "white"
            text:"输送速度"
        }

        Rectangle{
            anchors.verticalCenter: parent.verticalCenter
            anchors.right: parent.right
            anchors.rightMargin: 10
            radius: 10
            width: 320
            height: 40
            color: "#0088d0"

            Text{               // 输送速度显示
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                color: "white"
                text:Cpp_Connect.transducerSpeed
            }
        }
    }

    Rectangle{
        anchors.top: backGround.top
        anchors.topMargin: 1490
        anchors.left: backGround.left
        anchors.leftMargin: 10
        color: "#0b49b0"
        border.width: 1
        border.color: "#008edd"
        width: 480
        height: 70

        Text{
            anchors.top: parent.top
            anchors.topMargin: 20
            anchors.left: parent.left
            anchors.leftMargin: 10
            font.pixelSize: 30
            font.bold: true
            color: "white"
            text:"搜索配方"

        }

        Rectangle{
            anchors.top: parent.top
            anchors.topMargin: 10
            anchors.right: parent.right
            anchors.rightMargin: 10
            width: 320
            height: 50
            radius: 10
            color: "#0088d0"

            Text{
                id:search_Text
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                color: "white"
            }

            TextInput{      // 搜索配方输入框
                id:search_Input
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                visible: false
                color: "white"
                maximumLength: 13
                horizontalAlignment: Text.horizontalAlignment
                text:search_Text.text

                onAccepted: {
                    search_Input.visible = false
                    search_Text.visible = true
                    search_Text.text = search_Input.text
                    Cpp_Qmlengine.qmlSearchData(search_Text.text)
                }
            }

            MouseArea{
                anchors.fill: parent
                acceptedButtons: Qt.LeftButton
                //@disabel-check M16
                propagateComposedEvents: true

                onClicked: {
                    mouse.accepted = false
                    search_Text.visible = false
                    search_Input.visible = true
                    search_Input.forceActiveFocus()
                }
            }
        }        
    }
    Rectangle{
        anchors.top: backGround.top
        anchors.topMargin: 1580
        anchors.left: backGround.left
        anchors.leftMargin: 10
        color: "#0b49b0"
        border.width: 1
        border.color: "#008edd"
        width: 480
        height: 160

        Text{
            anchors.top: parent.top
            anchors.topMargin: 20
            anchors.left: parent.left
            anchors.leftMargin: 10
            font.pixelSize: 30
            font.bold: true
            color: "white"
            text:"客户公司"
        }

        Rectangle{
            anchors.top: parent.top
            anchors.topMargin: 10
            anchors.right: parent.right
            anchors.rightMargin: 10
            width: 320
            height: 50
            radius: 10
            color: "#0088d0"

            Text{
                id:company_Text
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                color: "white"
            }

            TextInput{      // 公司名称输入框
                id:company_Input
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                visible: false
                color: "white"
                maximumLength: 13
                horizontalAlignment: Text.horizontalAlignment
                text:company_Text.text

                onAccepted: {
                    company_Input.visible = false
                    company_Text.visible = true
                    company_Text.text = company_Input.text
                    // Cpp_Qmlengine.qmlSearchData(company_Text.text)
                }
            }

            MouseArea{
                anchors.fill: parent
                acceptedButtons: Qt.LeftButton
                //@disabel-check M16
                propagateComposedEvents: true

                onClicked: {
                    mouse.accepted = false
                    company_Text.visible = false
                    company_Input.visible = true
                    company_Input.forceActiveFocus()
                }
            }
        }

        Item{
            anchors.top: parent.top
            anchors.topMargin: 70
            anchors.left: parent.left
            anchors.leftMargin: 10

            RadioButton{
                id:wh_printButton
                anchors.top: parent.top
                text:"炜煌打印机"
                contentItem: Text{
                    leftPadding: wh_printButton.indicator.width
                    text:wh_printButton.text
                    font.pixelSize: 30
                    color: "white"
                }
            }
            RadioButton{
                id:rg_printButton
                anchors.top: wh_printButton.bottom
                anchors.topMargin: 5
                text:"瑞工打印机"
                contentItem: Text{
                    leftPadding: wh_printButton.indicator.width
                    text:rg_printButton.text
                    font.pixelSize: 30
                    color: "white"
                }
            }

        }


        Rectangle{      // 打印按钮
            anchors.top: parent.top
            anchors.topMargin: 70
            anchors.right: parent.right
            anchors.rightMargin: 10
            width: 200
            height: 80
            radius: 10
            color: "#2b6ec5"

            Text{
                anchors.centerIn:parent
                font.pixelSize: 30
                font.bold: true
                color: "white"
                text:"打印按钮"
            }

            MouseArea{
                anchors.fill: parent

                onPressed: {
                    parent.color = "#e44034"
                    if(wh_printButton.checked)
                    {
                        console.log("触发 - 炜煌打印机打印函数")
                        Cpp_Connect.printerActive(true,
                                                  company_Text.text,
                                                  selectName,
                                                  selectNumber,
                                                  w_knife,w_roller,
                                                  w_stress01,w_stress02,w_stress03,
                                                  w_fwdknife01,w_fwdknife02,w_fwdknife03,
                                                  w_backKnife01,w_backKnife02,w_backKnife03)
                    }
                    else if(rg_printButton.checked)
                    {
                        console.log("触发 - 瑞工打印机打印函数")
                        Cpp_Connect.printerActive(false,
                                                  company_Text.text,
                                                  selectName,
                                                  selectNumber,
                                                  w_knife,w_roller,
                                                  w_stress01,w_stress02,w_stress03,
                                                  w_fwdknife01,w_fwdknife02,w_fwdknife03,
                                                  w_backKnife01,w_backKnife02,w_backKnife03)
                    }

                }

                onReleased: {
                    parent.color = "#2b6ec5"
                    // Cpp_Connect.write_modbus_tcp_OneHoldingRegisters("2000","0")
                }
            }
        }

    }


    Rectangle{
        anchors.top: backGround.top
        anchors.topMargin: 1410
        anchors.right: backGround.right
        anchors.rightMargin: 10
        color: "#0b49b0"
        border.width: 1
        border.color: "#008edd"
        width: 560
        height: 220

        Rectangle{      // 参数加载到PLC按钮
            anchors.top: parent.top
            anchors.topMargin: 20
            anchors.left: parent.left
            anchors.leftMargin: 10
            width: 240
            height: 80
            radius: 10
            color: "#2b6ec5"

            Text{
                anchors.centerIn:parent
                font.pixelSize: 30
                font.bold: true
                color: "white"
                text:"加载选中参数"
            }

            MouseArea{
                anchors.fill: parent

                onPressed: {
                    parent.color = "#e44034"
                }

                onReleased: {
                    parent.color = "#2b6ec5"
                    Cpp_Connect.automaticPanel_OneKeyWriteParameter(w_knife,
                                                                    w_roller,
                                                                    w_stress01,
                                                                    w_stress02,
                                                                    w_stress03,
                                                                    w_fwdknife01,
                                                                    w_fwdknife02,
                                                                    w_fwdknife03,
                                                                    w_backKnife01,
                                                                    w_backKnife02,
                                                                    w_backKnife03);
                }
            }
        }


        Rectangle{      // 一键启动
            anchors.top: parent.top
            anchors.topMargin: 20
            anchors.right: parent.right
            anchors.rightMargin: 10
            width: 240
            height: 80
            radius: 10
            color: "#2b6ec5"

            Text{
                anchors.centerIn:parent
                font.pixelSize: 30
                font.bold: true
                color: "white"
                text:"一键启动"
            }

            MouseArea{
                anchors.fill: parent

                onPressed: {
                    parent.color = "#e44034"
                    Cpp_Connect.write_modbus_tcp_OneHoldingRegisters("2000","256")
                }

                onReleased: {
                    parent.color = "#2b6ec5"
                    Cpp_Connect.write_modbus_tcp_OneHoldingRegisters("2000","0")
                }
            }
        }


        Rectangle{      // 一键回原点
            anchors.top: parent.top
            anchors.topMargin: 120
            anchors.right: parent.right
            anchors.rightMargin: 10
            width: 240
            height: 80
            radius: 10
            color: "#2b6ec5"

            Text{
                anchors.centerIn:parent
                font.pixelSize: 30
                font.bold: true
                color: "white"
                text:"一键回待命点"
            }

            MouseArea{
                anchors.fill: parent

                onPressed: {
                    parent.color = "#e44034"
                    Cpp_Connect.write_modbus_tcp_OneHoldingRegisters("2004","1024")
                }

                onReleased: {
                    parent.color = "#2b6ec5"
                    Cpp_Connect.write_modbus_tcp_OneHoldingRegisters("2004","0")
                }
            }
        }

        Rectangle{      // 单轴回待命点界面(V 2.03版本已禁用  2025.01.19)
            anchors.top: parent.top
            anchors.topMargin: 120
            anchors.left: parent.left
            anchors.leftMargin: 10
            width: 240
            height: 80
            radius: 10
            color: "#2b6ec5"
            visible: false

            Text{
                anchors.centerIn:parent
                font.pixelSize: 30
                font.bold: true
                color: "white"
                text:"单轴回待命点"
            }

            MouseArea{
                anchors.fill: parent

                onPressed: {
                    parent.color = "#e44034"
                }

                onReleased: {
                    parent.color = "#2b6ec5"
                    Cpp_Connect.setQmlPage(2);
                    automaticPanel.visible = false
                    singleReturnPanel.visible = true
                }
            }
        }


        Rectangle{      // 错误位置确认(没有实际功能)
            // anchors.top: parent.top
            // anchors.topMargin: 220
            // anchors.horizontalCenter:  parent.horizontalCenter
            // // anchors.leftMargin: 10
            // width: 530
            // height: 80
            // radius: 10
            anchors.top: parent.top
            anchors.topMargin: 120
            anchors.left: parent.left
            anchors.leftMargin: 10
            width: 240
            height: 80
            radius: 10
            // color: "#2b6ec5"
            color: "#2b6ec5"

            Text{
                anchors.centerIn:parent
                font.pixelSize: 30
                font.bold: true
                color: "white"
                text:"错误位置确认"
            }

            MouseArea{
                anchors.fill: parent

                onPressed: {
                    parent.color = "#e44034"
                }

                onReleased: {
                    parent.color = "#2b6ec5"
                }
            }
        }



    }







}
